//
//  DR_FolderFilterCell.swift
//  DocReaderRP
//
//  Created by  mac on 2025/11/10.
//

import UIKit
import SnapKit

struct DR_FolderFilterModel {
    let title: String
    var isSelected: Bool
}

class DR_FolderFilterCell: UICollectionViewCell {
    
    static let identifier = "DR_FolderFilterCell"
    
    private let titleLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 15, weight: .regular)
        label.textColor = UIColor.white.withAlphaComponent(0.6)
        return label
    }()
    
    private let underlineView: UIView = {
        let view = UIView()
        view.backgroundColor = .white
        view.layer.cornerRadius = 1.5
        view.layer.masksToBounds = true
        view.isHidden = true
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        contentView.addSubview(titleLabel)
        contentView.addSubview(underlineView)
        
        // 确保 contentView 可以接收触摸事件
        contentView.isUserInteractionEnabled = true
        
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        
        underlineView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-2)
            make.width.equalTo(20)
            make.height.equalTo(3)
        }
    }
    
    func configure(with model: DR_FolderFilterModel) {
        titleLabel.text = model.title
        
        if model.isSelected {
            titleLabel.font = UIFont.systemFont(ofSize: 18, weight: .medium)
            titleLabel.textColor = .white
            underlineView.isHidden = false
        } else {
            titleLabel.font = UIFont.systemFont(ofSize: 18)
            titleLabel.textColor = UIColor.white.withAlphaComponent(0.3)
            underlineView.isHidden = true
        }
    }
}

